#ifndef LOGGER_H
#define LOGGER_H

#if defined(__unix__)
#include <unistd.h>
#elif defined(_MSC_VER)
#include <windows.h>
#endif

#include <stdio.h>

// #define ELPP_THREAD_SAFE 
#include "easylogging++.h"
#define ELPP_THREAD_SAFE 


//
// win32  预处理器添加宏  _CRT_SECURE_NO_DEPRECATE
//

#define LOG_TRACE(fmt, ...)                                                                 \
    do                                                                                      \
    {                                                                                       \
        char buf[1024] = {0};                                                               \
        sprintf(buf, "[%s:%d:%s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
        LOG(TRACE) << buf;                                                                  \
    } while (0);

#define LOG_DEBUG(fmt, ...)                                                                 \
    do                                                                                      \
    {                                                                                       \
        char buf[1024] = {0};                                                               \
        sprintf(buf, "[%s:%d:%s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
        LOG(DEBUG) << buf;                                                                  \
    } while (0);

#define LOG_INFO(fmt, ...)                                                                  \
    do                                                                                      \
    {                                                                                       \
        char buf[1024] = {0};                                                               \
        sprintf(buf, "[%s:%d:%s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
        LOG(INFO) << buf;                                                                   \
    } while (0);

#define LOG_WARNING(fmt, ...)                                                               \
    do                                                                                      \
    {                                                                                       \
        char buf[1024] = {0};                                                               \
        sprintf(buf, "[%s:%d:%s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
        LOG(WARNING) << buf;                                                                \
    } while (0);

#define LOG_ERROR(fmt, ...)                                                                 \
    do                                                                                      \
    {                                                                                       \
        char buf[1024] = {0};                                                               \
        sprintf(buf, "[%s:%d:%s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
        LOG(ERROR) << buf;                                                                  \
    } while (0);

#define LOG_FATAL(fmt, ...)                                                                 \
    do                                                                                      \
    {                                                                                       \
        char buf[1024] = {0};                                                               \
        sprintf(buf, "[%s:%d:%s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
        LOG(FATAL) << buf;                                                                  \
    } while (0);

#define EASY_LOG(LEVEL, fmt, ...) LOG_##LEVEL(fmt, ##__VA_ARGS__)

namespace LogConsole
{
    void LogDump(const char *tag, int num, ...);
#if defined(_MSC_VER)
    void WinConsolePrint(const char *str);
#endif
}

#define LOG_PRINT(fmt, ...)                                                          \
    do                                                                                     \
    {                                                                                      \
        printf("[%s:%d:%s()] " fmt "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
    } while (0)

// #define MYLOG(str)
// #define MYLOG(fmt, ...) LOG_PRINT(fmt, ##__VA_ARGS__) // 这里选用控制台打印来测试   increase thread  和  decrease thread, 原因如下所述,
#define MYLOG(fmt, ...) LOG_INFO(fmt, ##__VA_ARGS__)
//

#endif // LOGGER_H
